package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ShopsDaysQuery;
import com.xingkeduo.pojo.table.ShopsDaysTable;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ShopsDaysService {
    private static final String NAMESPACE = ShopsDaysTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ShopsDaysTable, ShopsDaysQuery> dao;

    //查询一条
    public ShopsDaysTable selectByCode(long code) throws Throwable {
        ShopsDaysTable shopsDaysTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(shopsDaysTable))
            return shopsDaysTable;
        return null;
    }
    //根据店铺ID查询
    public ShopsDaysTable selectShopId(long id) throws Throwable {
        ShopsDaysTable shopsDaysTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(shopsDaysTable))
            return shopsDaysTable;
        return null;
    }


    //查询多条
    public List<ShopsDaysTable> selectLists(ShopsDaysQuery shopsDaysQuery) throws Throwable {
        List<ShopsDaysTable> shopsDaysTableList = dao.select(NAMESPACE, shopsDaysQuery);
        if (!CommonUtil.isEmpty(shopsDaysTableList))
            return shopsDaysTableList;
        return null;
    }

    //插入
    public int insert(ShopsDaysTable shopsDaysTable) throws Throwable {
        shopsDaysTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, shopsDaysTable);
    }
    //批量插入
    public int insertAll(List<ShopsDaysTable> shopsDaysList) throws Throwable {
//        shopsDaysTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, shopsDaysList);
    }

    //更新
    public int update(ShopsDaysTable shopsDaysTable) throws Throwable {
        return dao.update(NAMESPACE, shopsDaysTable);
    }

    //删除
    public int delete(ShopsDaysTable shopsDaysTable) throws Throwable {
        return dao.update(NAMESPACE, shopsDaysTable);
    }
}
